/**
 * Eclipse Outliner
 * Copyright (C) 2006 Jeff Mesnil
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package net.jmesnil.opml.core.internal;

import java.util.Date;

import net.jmesnil.opml.core.IHead;
import net.jmesnil.opml.core.IOwner;

public class Head implements IHead {

    private String title;

    private IOwner owner;

    private Date creation;

    private Date lastModification;

    public Head(String title, IOwner owner, Date creation, Date lastModification) {
        this.title = title;
        this.owner = owner;
        this.creation = creation;
        this.lastModification = lastModification;
    }

    public Date getCreation() {
        return creation;
    }

    public Date getLastModification() {
        return lastModification;
    }

    public IOwner getOwner() {
        return owner;
    }

    public String getTitle() {
        return title;
    }

    public String toXML() {
        StringBuffer buff = new StringBuffer("<head>\n");
        if (!"".equals(title)) {
            buff.append("    <title>").append(title).append("</title>\n");
        }
        buff.append("    <dateCreated>").append(creation).append(
                "</dateCreated>\n");
        buff.append("    <dateModified>").append(new Date()).append(
                "</dateModified>\n");
        if (owner != null) {
            if (!"".equals(owner.getName())) {
                buff.append("    <ownerName>").append(owner.getName()).append(
                        "</ownerName>\n");
            }
            if (!"".equals(owner.getId())) {
                buff.append("    <ownerId>").append(owner.getId()).append(
                        "</ownerId>\n");
            }
            if (!"".equals(owner.getEmail())) {
                buff.append("    <ownerEmail>").append(owner.getEmail())
                        .append("</ownerEmail>\n");
            }
        }
        buff.append("</head>\n");
        return buff.toString();
    }
}
